
library(tidyverse)
library(readxl)
library(ggplot2)


df <- read_csv('Source data/exports.csv')

df <- df %>%
  filter(Date >= '2014-01-01') %>%
  mutate(value = USD_THOU/1000)

ggplot(df, 
       aes(x = Date, y = value)) +
  geom_point() +
  geom_smooth()

df_pre <- df %>%
  filter(Date <= '2016-06-01') 
#df_pre$Date <- as.numeric(df_pre$Date)
df_post <- df %>%
  filter(Date >= '2016-06-01')
#df_post$Date <- as.numeric(df_post$Date)


p <- ggplot() +
  geom_point(data = df_pre, aes(x = Date, y = value)) +
  geom_smooth(data = df_pre, aes(x = Date, y = value)) +
  geom_point(data = df_post, aes(x = Date, y = value)) +
  geom_smooth(data = df_post, aes(x = Date, y = value)) +
  geom_vline(xintercept = as.Date("2016-06-01"),
             linetype = 2, colour = "black") + 
  labs(caption = 'Note: Vertical line indicates the start \nof the USDA Hass Avocado Import Program',
       x = 'Year',
       y = 'Value of Avocado Exports \n(in millions of USD)') + 
  theme_minimal() + 
  theme(axis.title.x = element_text(size = 15),
        axis.title.y = element_text(size = 15),
        plot.caption = element_text(size = 12),
        axis.text.x = element_text(size = 12),
        axis.text.y = element_text(size = 12))
p  
  
ggsave("Outputs/plots/Fig2_avocado_exports.pdf", plot = p, width = 782/72, height = 396/72)
